package com.activiti.controller;

import com.activiti.reqentity.DeploymentResponse;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.repository.Model;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.ArrayList;
import java.util.List;


@Controller
public class IndexController {
    @Autowired
    RepositoryService repositoryService;

    @GetMapping("/index")
    public String index(ModelMap modelMap){
        List<Model> flowList = repositoryService.createModelQuery().list();
        modelMap.put("flowList",flowList);
        List<Deployment> deployments = repositoryService.createDeploymentQuery().list();
        List<DeploymentResponse> deployList = new ArrayList<>();
        for (Deployment deployment : deployments){
            deployList.add(new DeploymentResponse(deployment));
        }
        modelMap.put("deployList",deployList);
        return "/index";
    }

    @GetMapping("/editor")
    public String test(){
        return "/modeler";
    }

}
